from django.core.mail import send_mail
from django.template import loader

from django09_1.settings import EMAIL_HOST_USER


def make_email(name,email,token):
    # host: EMAIL_HOST
    # port: EMAIL_PORT
    # username: EMAIL_HOST_USER
    # password: EMAIL_HOST_PASSWORD

    # send_mail( subject, message, from_email, recipient_list,)
    # 主题
    subject = '激活'
    # 邮件的内容
    message = '邮件来了'

    # 加载
    index = loader.get_template('axf/user/register/active.html')
    # 渲染
    context = {
        'name': name,
        'url': 'http://123.57.244.100:8000/axfuser/account/?token='+str(token)
    }
    # html格式的内容
    html_message = index.render(context=context)

    # 发送者
    from_email = EMAIL_HOST_USER
    # 接受者 必须为列表[]
    recipient_list = [email,]

    send_mail(subject=subject,
              message=message,
              html_message=html_message,
              from_email=from_email,
              recipient_list=recipient_list,
            )